<%--
    Document   : help
    Created on : Apr 20, 2013, 2:31:04 PM
    Author     : TNT
--%>

<%@page import="java.sql.*"%>
<%@page import="RMI.Client"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Tìm kiếm sản phẩm</title>
        <%@page import="RMI.Client"%>
        
        </SCRIPT>
    </head>
    <body bgcolor="#CCFFFF">
        
  <table width="1024" border="0" align =center cellSpacing=0 cellPadding=0 bgcolor='white'>
  <tr>
      <td colspan="5"><div align="center"><a href ="index.jsp"> <img src ="image/laptops_banner.jpg" width ="1024px" height="150" ></a></div></td>
  </tr>
  <tr>
    <td colspan="5"><%@include file="menu_ngang.jsp" %></td>
  </tr>
  <tr>
      <td width="150" vAlign=top bgcolor ="silver" ><div align ="center"><%@include file="menu_doc.jsp" %></div></td>
    <td width="4">&nbsp;</td>
    <td width='720' vAlign=top >
    <%
        String name = request.getParameter("name");
	String provider = request.getParameter("provider");
	String price = request.getParameter("cost");
	String query = "select * from product where Name like'%"+name+"%' or (Provider='"+provider+"' and Cost >='"+price+"')";
	Class.forName("com.mysql.jdbc.Driver");
	Connection con = null;
	Statement smt = null;
	ResultSet rst = null;
	int i = 0;
	try {
		String username = "root";
		String password = "root";
		String url = "jdbc:mysql://127.0.0.1:3306/laptop";
		con = DriverManager.getConnection(url, username, password);
		smt = con.createStatement();
		rst = smt.executeQuery(query);
		out.print("<table width="+"720"+" height="+"100%"+" border="+"0"+">");
		if (!rst.next()) out.println("<tr><td>Không có sản phẩm tương ứng</td></tr>");
		else rst.beforeFirst();
		while (rst.next()) {
			if(i%3 == 0) out.print("<tr>");			
			out.println("<td width=240 align=center>"+"<img src="+rst.getString(5)+" "
                                + "width=200><br>"+rst.getString(2)+"<br><a href="+"productdetail.jsp?ID="+
                                rst.getString(1)+">Chi tiết</a></td>");
			i++;
			if(i%3 == 0) out.print("</tr>");
		}
		out.print("</table>");
		con.close();
	} catch (Exception e) {}
                            
    %>
    <td width="2">&nbsp;</td>
    <td width="150" vAlign=top ><%@include file="Right.jsp" %></td>
  </tr>
  <tr>
      <td colspan="5"><%@include file="bottom.jsp" %></td>
  </tr>
</table>
</body>
</html>
